
$(function(){
 tabPanel_nav();
});

function tabPanel_nav (){
    var rstartX,_rleft;
    $(".news-nav").bind("touchstart",function(e){
		var touch = event.touches[0];
		rstartX = touch.pageX;
		var offset = $(this).offset();
		_rleft = offset.left;
	  });

    $(".news-nav").bind("touchmove",function(e){
      e.preventDefault();
      var touch = event.touches[0];
      var x = touch.pageX-rstartX;
      var offset = _rleft + x;
      $(this).offset({left:offset});
    });
     
    $(".news-nav").bind("touchend",function(e){
     // var top = $(this).offset().top;
	 var left = $(this).position().left;
      var ww = $(this).width();
      var fw = $(this).parent().width();
      var stopx=Math.abs(ww-fw);
      if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){
        if($(this).outerWidth()<=$(this).parent().outerWidth()){
			$(this).animate({left: 0}, "fast");	
         }else{
			  if(left>0){//向下
				$(this).animate({left: 0}, "fast");
			   }else if(left <stopx*(-1)){
				  $(this).animate({left: -stopx-1}, "fast");
			  }
         }

       }else{
             if($(this).outerWidth()<=$(this).parent().outerWidth()){
				  $(this).animate({left: 0}, "fast");	
			   }else{
					if(left>0){//向下
					  $(this).animate({left: 0}, "fast");
					 }else if(left <stopx*(-1)){
						$(this).animate({left: -stopx}, "fast");
					}
			   }
           }
    
    });
}
